import EventFul from "/core/eventFul";
import { Layer } from "/core/layer";
import TaskQueue from "/core/taskQueue";
import { Grender } from "/grender";
import Node from "/core/node";
import { Graphic } from "../type";
import { EventName } from "/enum/eventEnum";
import { EventCallback } from "/types/event";
import mixins, { drawImage } from "/mixin/shape";
import { NodeType } from "/enum/NodeTypeEnum";

export interface ShapeProps {
	draggable?: boolean;
	type?: NodeType;
	[key: string]: any;
}
export interface ShapeConfig {
	drawImg?: HTMLImageElement;
	drawX?: number;
	drawY?: number;
	drawOffsetX?: number;
	drawOffsetY?: number;
}
export class Shape extends Node<Graphic, Layer> {
	bindRender: Layer; //绑定的layer
	draggable: boolean;
	renderQueue: TaskQueue;
	layer: Layer;
	eventFul: EventFul;
	config: ShapeConfig = {};
	constructor(shapeProps: ShapeProps={}) {
		const { draggable = false, ...props } = shapeProps;
		super(props);

		Object.assign(this, new EventFul());
		this.draggable = draggable;
		//创建队列
		this.renderQueue = new TaskQueue();
		this.eventFul = new EventFul();
	}
	on(names: EventName, listener: EventCallback) {
		this.eventFul.on(names, listener);
	}
	off(names?: EventName) {
		this.eventFul.off(names);
	}
	stopPropagation = () => {
		this.eventFul.stopPropagation();
	};
	bingContext(layer: Layer) {
		this.layer = layer;
	}
}
mixins(Shape);
